package chapter27;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/28 20:48
 */
public class InstantTest {
    public static void main(String[] args) {
        System.out.println(Instant.now());
        Instant instant = Instant.ofEpochMilli(System.currentTimeMillis());
        System.out.println(instant);

        System.out.println(toBeijingIntant(LocalDateTime.now()));
    }

    private static Instant toInstant(Date date) {
        return Instant.ofEpochMilli(date.getTime());
    }

    private static Date toDate(Instant instant) {
        return new Date(instant.toEpochMilli());
    }

    private static Instant toBeijingIntant(LocalDateTime dateTime) {
        return dateTime.toInstant(ZoneOffset.of("+08:00"));
    }
}
